﻿
namespace System.Linq
{
    public class Identifier
    {
        public long Id { get; private set; }

        public long Revision { get; private set; }

        public Identifier(long id, long revision)
        {
            Id = id;
            Revision = revision;
        }

        public bool IsEmpty
        {
            get { return this == Empty; }
        }

        private static Identifier _empty = new Identifier(0, 0);
        static Identifier() { }
        public static Identifier Empty
        {
            get { return _empty; }
        }

        public static bool operator ==(Identifier a, Identifier b)
        {
            if (System.Object.ReferenceEquals(a, b))
                return true;
            if (((object)a == null) || ((object)b == null))
                return false;
            return a.Id == b.Id && a.Revision == b.Revision;
        }

        public static bool operator !=(Identifier a, Identifier b)
        {
            return !(a == b);
        }

        public override bool Equals(object obj)
        {
            bool res = false;
            if (obj is Identifier)
                res = ((Identifier)obj).Id == this.Id && ((Identifier)obj).Revision == this.Revision;
            return res;
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int hash = 17;
                hash = hash * 23 + Id.GetHashCode();
                hash = hash * 23 + Revision.GetHashCode();
                return hash;
            }
        }

        public override string ToString()
        {
            return string.Format("{0}({1})", Id, Revision);
        }
    }
}